package com.huahang.fashionpress.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huahang.fashionpress.enums.ExceptionEnum;
import com.huahang.fashionpress.exception.RoleException;
import com.huahang.fashionpress.mapper.NickroleMapper;
import com.huahang.fashionpress.mapper.RoleMapper;
import com.huahang.fashionpress.model.NickRole;
import com.huahang.fashionpress.model.Role;
import com.huahang.fashionpress.service.RoleService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: 阿俊哥
 * @Date: 2019/8/28 19:00
 * @Version 1.0
 */
@Transactional
@Service
public class RoleServiceImpl implements RoleService {

    @Resource
    RoleMapper roleMapper;

    @Resource
    NickroleMapper nickroleMapper;
    @Override
    public List<Role> selectRoleList(int nickId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("nick_id", nickId);
        List<NickRole> nickRoles = nickroleMapper.selectList(queryWrapper);
        if(nickRoles==null){
            throw  new RoleException(ExceptionEnum.NOT_EXIT_ROLE);
        }
        List<Role> roleList = new ArrayList<>();
        for (NickRole nickRole :nickRoles
             ) {
            Role role  = roleMapper.selectById(nickRole.getRoleId());
            roleList.add(role);

        }
       return  roleList;
    }
}
